Skip to content

Host core: tell hosts when the renderer is ready and when the frames have painted - #122

Merged
agorischek merged 3 commits into
mainfrom
renderer-status-events
Nov 21, 2026
Merged

agorischek merged 3 commits into
mainfrom
renderer-status-events

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Stacked on #115 (the playback machine). I built it on #115 because the State machine survey session asked that use-projection.ts be left alone until #115 merges; building on it avoids the conflict instead. This is item G2 of the headless-host plan ("status events").

Why

The controller had no way to say "the renderer is ready" or "the frames have drawn". Hosts read it from the view's DOM:

  • the hosted site's carousel (hosted/service/src/landing-carousel.tsx:81-95, private) puts a MutationObserver on data-renderer-status;
  • the Playground tour (src/github/tour-playback.ts:93-106, private) observes data-progress, data-comparison-mode, data-renderer-status and data-rendered-progress;
  • the githubnext.com poster-to-live handover has the same need. The state-machine survey's step 8 is blocked on these events.

So every UI had to hand-copy those data attributes as an informal contract.

What changed

  • ProjectionOptions.onRendererStatusChange(status) is called whenever rendererStatus changes, and with the first value.

  • ProjectionController.paint (PaintState) and the pure paintState(controller):

    • none without a renderer;
    • loading or failed while a shown pane is;
    • painting until every shown pane has acknowledged painting what it was sent: in two-pane modes the start (before pane) and the end (after pane), in Animated the current progress;
    • then painted.

    This generalises the Inspector snapshot page's private painted check.

  • ProjectionOptions.onPainted({mode, progress}) is called once each time the frames settle on what's shown while paused: after a load, a mode change, a seek or the end of playback.

  • projection/paint.ts is new. use-projection.ts gains one hook call and the paint field, and doesn't touch Host core: playback's lifecycle as a state machine, with one stop path #115's playback code.

The State machine survey session agreed these names. If the pane status becomes a machine later, they become its effects.

Follow-ups

  • Private: move the carousel and the tour onto onRendererStatusChange and onPainted, which removes their MutationObservers.
  • Public: the Inspector's snapshotReadiness can use paintState for its painted check.

Docs and tests

  • docs/guides/host-core.md gains "Status events".
  • packages/host/core/test/paint.test.mjs (node:test, 3 tests) covers paintState in Animated, two-pane modes, one extraction and diff.

Run locally:

  • tools check --fast: pass.
  • tsc for core: pass, with packages/machine built.
  • node --test test/paint.test.mjs test/playback-lifecycle.test.mjs: 9/9.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A stale Animated pane acknowledgement can trigger onPainted before Diff is drawn and again afterward, causing hosts to capture or reveal the wrong frame.

1 open issue
What changed in this PR

Adds renderer-status and paint-readiness signals to the headless host core so hosts can wait for rendered content without observing DOM attributes. This builds on the playback state-machine work without changing its logic.

Changes:

  • Adds onRendererStatusChange and paused-frame onPainted callbacks.
  • Exposes controller paint state and the pure paintState helper.
  • Documents the API and adds paint-state tests.
File Description
packages/​host/​core/​test/​paint.test.mjs Tests readiness across modes and pane states.
packages/​host/​core/​src/​projection/​use-projection.ts Connects paint readiness and status events to the controller.
packages/​host/​core/​src/​projection/​types.ts Defines the new callback options and controller field.
packages/​host/​core/​src/​projection/​paint.ts Implements paint-state calculation and status callbacks.
packages/​host/​core/​src/​index.ts Exports the paint helper and public types.
docs/​guides/​host-core.md Documents status events and paint readiness.

Review effort: Balanced

@agorischek
agorischek force-pushed the renderer-status-events branch from 5bae76b to 8717cf9 Compare November 21, 2026 01:07
@agorischek
agorischek force-pushed the host-playback-machine branch from 08b201a to 78a9788 Compare November 21, 2026 01:40
Base automatically changed from host-playback-machine to main November 21, 2026 04:19
agorischek and others added 2 commits November 21, 2026 07:19
…have painted

Hosts that wait on the renderer read it from the view's DOM: the hosted site's carousel and the Playground's tour
observe `data-renderer-status` and `data-rendered-progress` with a MutationObserver, and a poster-to-live handover has
nothing else to go on. The core now says so itself:

- `onRendererStatusChange(status)`, with the first status too;
- `paint` on the controller and the pure `paintState(controller)`: `none`, `loading`, `failed`, `painting` or
  `painted`, once every shown pane has acknowledged painting what it was sent;
- `onPainted({mode, progress})`, once each time the frames settle on what is shown while paused.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…as painted

Switching a paused Animated view to Diff kept the Animated acknowledgement in `panes.main.rendered` for a render, so
`paint` read `painted` and `onPainted` fired before Diff was drawn (and again after). A pane's `rendered` now
records the init it answers (`renderedInit`), and `paintState` ignores one for an earlier init.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek force-pushed the renderer-status-events branch from 8717cf9 to e6a816e Compare November 21, 2026 15:19
@agorischek
agorischek merged commit 4a40e67 into main Nov 21, 2026
82 of 84 checks passed
@agorischek
agorischek deleted the renderer-status-events branch November 21, 2026 16:45
agorischek added a commit that referenced this pull request Nov 21, 2026
…#146)

useProjection's onRendererStatusChange and onPainted (#122) weren't
ProjectionView props, so a host using the prebuilt view still had to
observe its data-renderer-status attribute. The view now takes both and
forwards them.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants